package com.brillilab.starter.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import com.brillilab.starter.handler.PowerInterceptor;

@Configuration
public class MyInterceptorConfig extends WebMvcConfigurationSupport {

    //关键，将拦截器作为bean写入配置中，不能直接new,否则拦截器无法注入服务
    @Bean
    public PowerInterceptor powerInterceptor() {
        return new PowerInterceptor();
    }

    /**
     * 多个拦截器组成一个拦截器链
     * addPathPatterns 用于添加拦截规则
     * excludePathPatterns 用户排除拦截
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //权限校验拦截器
        registry.addInterceptor(powerInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/static/**")
                .excludePathPatterns("/**/*.html")
                .excludePathPatterns("/**/*.js")
                .excludePathPatterns("/**/*.css")
                .excludePathPatterns("/error")
                .excludePathPatterns("/api/sms/*")
                .excludePathPatterns("/api/email/*")
                .excludePathPatterns("/**/*Login")
                .excludePathPatterns("/*/user/register")
                .excludePathPatterns("/*/user/*Register")
                .excludePathPatterns("/*/user/*SmsCode")
                .excludePathPatterns("/*/user/bindLab")
                .excludePathPatterns("/*/user/forget")
                .excludePathPatterns("/*/user/forget/*")
                .excludePathPatterns("/*/user/info")
                .excludePathPatterns("/*/lab/device")
                .excludePathPatterns("/*/labMember/list")
                .excludePathPatterns("/*/labMember/empowerVerify")
                .excludePathPatterns("/*/kitUsage/usage/list")
                .excludePathPatterns("/*/usage/inventory/return")
                .excludePathPatterns("/*/kitUsage/usage/inventroy")
                .excludePathPatterns("/*/system/duty")
                .excludePathPatterns("/*/system/duties")
                .excludePathPatterns("/employee/**")
                .excludePathPatterns("/employee")
                .excludePathPatterns("/es/reagent/**")
                .excludePathPatterns("/es/kit/**")
                .excludePathPatterns("/download/**")
                .excludePathPatterns("/upload/callback")
                .excludePathPatterns("/*/labUserCard/cardToDo")
                .excludePathPatterns("/*/kitUsage/*/lock")
                .excludePathPatterns("/*/labUserCard/memberCardList")
                .excludePathPatterns("/*/spaceManage/device/listByAioDeviceNo")
                .excludePathPatterns("/*/spaceManage/device/allDeviceList")
                .excludePathPatterns("/api/fileManage/callback")
                .excludePathPatterns("/api/fileManage/getAutoDownFilesAIO")
                .excludePathPatterns("/api/fileManage/uploadFile")
                .excludePathPatterns("/api/fileManage/fileDecryptTemp")
                .excludePathPatterns("/*/system/warnamount")
                .excludePathPatterns("/*/system/zone")
                .excludePathPatterns("/*/system/unit")
                .excludePathPatterns("/*/system/getDutyYearList")
                .excludePathPatterns("/*/system/reagentFieldData")
                .excludePathPatterns("/*/system/version")
                .excludePathPatterns("/*/system/health")
                .excludePathPatterns("/*/system/getDutyList")
                .excludePathPatterns("/*/system/getLearningEmailSuffixList")
                .excludePathPatterns("/*/lab/aio/login")
                .excludePathPatterns("/es/**")
                .excludePathPatterns("/api/crm/**")
                .excludePathPatterns("/api/applyLab/**")
                .excludePathPatterns("/api/userInviteAudit/checkInviteReg")
                .excludePathPatterns("/api/userInviteAudit/submitLabMemberAudit")
                .excludePathPatterns("/api/userInviteAudit/applyJoinLab")
                .excludePathPatterns("/api/system/customServiceInfo")
                .excludePathPatterns("/*/user/modifyPwd")
                .excludePathPatterns("/web/applyLab/**")
                .excludePathPatterns("/*/organization/list")
                .excludePathPatterns("/crm/user/login")

        ;

    }

    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        //静态资源访问配置
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        super.addResourceHandlers(registry);
    }

}